import axios from 'axios'
import store from '@/store/index'
import {
	Toast
} from 'vant';
// 创建axios实例
const service = axios.create({
	baseURL: myConfig.xuhuiAndroidURL,
	timeout: 60000,
	method: 'get',
})
// request拦截器
service.interceptors.request.use(config => {
	// config.params={
	// 	...config.data,
	// 	serviceUrl:`http://${store.state.deviceInfo.ipAddr}:38089/api${config.url}`,
	// 	httpMethod:config.params&&config.params.httpMethod||'get',
	// }
	// config.url='/ExecuteCommonPostJson'
	config.data={
		...config.data
	}
	if(config.params){
		config.method=config.params.httpMethod;
	}
	return config
}, error => {
	console.log(error)
	Promise.reject(error)
})

// 响应拦截器
service.interceptors.response.use(res => {
		let result = res.data;
		if (result.code == "0") {
			result = {
				success: true,
				data: result.data,
				msg: result.msg,
			}
		} else {
			result = {
				success: false,
				msg: result.msg
			}
			// Toast({
			// 	message: result.msg || '安卓业务出错',
			// });
		}
		return result
	},
	error => {
		Toast({
			message: error.message || '服务出错',

		});
		return error
	}
)
export default service